<template>
	<div class="box">
		<u-form size="medium" ref="itemForm" :model="obj" label-width="100px">
			<u-form-item label="订单编号">{{ orderno }}</u-form-item>
			<u-form-item label="订单价格">{{ money }}</u-form-item>
			<u-form-item label="变化类型">
				<u-radio-group v-model="obj.type">
					<u-radio :name="0" label="增加"></u-radio>
					<u-radio :name="1" label="减少"></u-radio>
				</u-radio-group>
			</u-form-item>

			<u-form-item label="变更金额" prop="money"><u-input placeholder="变更金额" v-model="obj.money" style="width:200px;"></u-input></u-form-item>

			<!-- <u-form-item label="操作备注" prop="remark">
        <el-input placeholder="变更备注" v-model="obj.remark" type="textarea" rows="2"></el-input>
      </u-form-item> -->

			<u-form-item label="管理员密码" prop="password"><u-input placeholder="请输入操作员密码" type="password" v-model="obj.password"></u-input></u-form-item>
		</u-form>
		<view class="u-flex u-flex-items-center footer">
			<u-button size="small" shape="circle" @click="close">取消</u-button>
			<u-button class="u-m-l-60" type="primary" size="small" shape="circle" @click="saveData">确定</u-button>
		</view>
	</div>
</template>
<script>
export default {
	name: 'editMoney',
	data() {
		return {
			isLoading: false,
			orderno: '',
			money: '',
			obj: {
				id: '',
				type: 0, //变化类型:0:增加,1:减少,2:最终金额
				money: 0,
				password: '',
				update_time: ''
			},
			itemRules: {
				remark: [
					{
						required: true,
						message: '请输入备注'
					}
				],
				password: [
					{
						required: true,
						message: '请输入管理员密码'
					}
				],
				money: [
					{
						required: true,
						message: '请输入变更金额'
					}
				]
			}
		};
	},
	created() {},
	methods: {
		//初始化
		init(id) {
			this.isEdit = true;
			this.isLoading = true;
			uni.$u.http
				.get('/shop/order/' + id, {custom:{id:8}})
				.then(res => {
					this.isLoading = false;
					let o = res.msg;
					//赋值数据
					this.orderno = o.order_no;
					this.money = o.money;
					this.obj.id = o.id;
					this.obj.update_time = o.update_time;
					this.$refs.itemForm.setRules(this.itemRules);
				})
				.catch(e => {
					this.isLoading = false;
				});
		},
		//保存数据(修改发货地址)
		saveData() {
			this.$refs.itemForm.validate().then(res => {
				let o = {...this.obj};
				//特殊处理字段
				o.num = parseFloat(o.num);
				this.isLoading = true;
				uni.$u.http
					.put('/shop/order/changeMoney', o,{custom:{id:8}})
					.then(res => {
						this.isLoading = false;
						this.$emit('success');
					})
					.catch(e => {
						this.isLoading = false;
					});
			});
		},
		close() {
			this.$emit('close', 'showMoneyEdit');
		}
	}
};
</script>

<style lang="scss" scoped>
.u-form-item {
	margin-bottom: 15px;
}
</style>
